var btnList = Vue.component('btn-page', {
    template: "#btnPage",
    methods: {},
    mounted: function () {

    }
});
var index = Vue.component('index-page', {
    template: "#index",
    data:function(){
        return{
            arr1:[
                {aa:111,id:'1'},
                {aa:55,id:'1'},
                {aa:33,id:'1'},
                {aa:22},
                {aa:22,iddd:'23'},
            ]
        }
    },
    methods: {
        go_page: function () {
            router.push({path: '/contacts', query: {id: 11}});
        }
    },
    mounted: function () {

    }
});
var calendar = Vue.component('calendar', {
    template: "#calendar",
    data: function () {
        return {
            currentDay: 1,
            currentMonth: new Date().getMonth() - 1,
            currentYear: new Date().getFullYear(),
            currentWeek: 1,
            days:[],
        }
    },
    methods: {
        // 日历组件
        initData: function (cur) {
            var date;
            if (cur) {
                date = new Date(cur);
            }
            else {
                date = new Date();
            }
            this.currentDay = date.getDate();
            this.currentYear = date.getFullYear();
            this.currentMonth = date.getMonth() + 1;
            this.currentWeek = date.getDay() + 1; // 1...6,0
            if (this.currentWeek == 0) {
                this.currentWeek = 7;
            }
            var str = this.formatDate(this.currentYear, this.currentMonth, this.currentDay);
            this.days.length = 0;
            // 今天是周日，放在第一行第7个位置，前面6个
            for (var i = this.currentWeek; i >= 0; i--) {
                var d = new Date(str);
                d.setDate(d.getDate() - i);
                this.days.push(d);
            }
            for (var i = 1; i <= 41 - this.currentWeek; i++) {
                var d = new Date(str);
                d.setDate(d.getDate() + i);
                this.days.push(d);
            }
        },
        pickPre: function (year, month) {
            var d = new Date(this.formatDate(year, month, 1));
            d.setDate(0);
            var date = this.formatDate(d.getFullYear(), d.getMonth() + 1, 1);
            this.initData(date);
        },
        pickNext: function (year, month) {
            var d = new Date(this.formatDate(year, month, 1));
            d.setDate(35);
            var date = this.formatDate(d.getFullYear(), d.getMonth() + 1, 1);
            this.initData(date);
        },
        formatDate: function (year, month, day) {
            // 返回 类似 2016-01-02 格式的字符串
            var y = year;
            var m = month;
            if (m < 10) m = "0" + m;
            var d = day;
            if (d < 10) d = "0" + d;
            return y + "-" + m + "-" + d
        },
        today_flag:function(val){
            var flag = false;
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            var year2 = val.getFullYear();
            var month2 = val.getMonth() + 1;
            var day2 = val.getDate();
            if (year == year2 && month == month2 && day == day2){
                  flag = true;
            }
            return flag;
        },
        other_month:function(val){
            var flag = true;
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var year2 = val.getFullYear();
            var month2 = val.getMonth() + 1;
            if (year == year2 && month == month2){
                flag = false;
            }
            return flag;
        }
    },
    mounted: function () {
        this.initData();
        this.pickPre(this.currentYear,this.currentMonth);
        this.pickNext(this.currentYear,this.currentMonth);
    }
});